<?php
class Address extends AppModel {
    var $name = 'Address';
    var $primaryKey = 'address_id';
    var $displayField =  'street';

    var $hasOne = array(
        'Building',
        'Person'
    );

    var $belongsTo = array(
        'AddressProvince' => array(
            'className' => 'Territory',
            'foreignKey' => 'province_id',
            'conditions' => array('AddressProvince.territory_type' => 'PROVINCE'),
            'order' => 'AddressProvince.territory_name DESC'
        ),
        'AddressCity' => array(
            'className' => 'Territory',
            'foreignKey' => 'city_id',
            'conditions' => array('AddressCity.territory_type' => 'CITY'),
            'order' => 'AddressCity.territory_name DESC'
        ),
        'AddressNeighborhood' => array(
            'className' => 'Territory',
            'foreignKey' => 'neighborhood_id',
            'conditions' => array('AddressNeighborhood.territory_type' => 'NEIGHBORHOOD'),
            'order' => 'AddressNeighborhood.territory_name DESC'
        )
    );
}
?>
